package com.sctu.edu.tracks.adapter;

import android.app.Activity;
import android.os.Bundle;
import android.text.LoginFilter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sctu.edu.tracks.R;
import com.sctu.edu.tracks.RecordDetailsActivity;
import com.sctu.edu.tracks.bean.RecordListBean;
import com.sctu.edu.tracks.utils.DateUtils;
import com.sctu.edu.tracks.utils.JumpUtils;
import com.sctu.edu.tracks.utils.L;

import java.util.List;

/**
 * Created by zhengsenwen on 2017/5/25.
 */
public class RecordAdapter extends BaseAdapter {

    private Activity activity;
    private List<RecordListBean.Data> list;

    public RecordAdapter(Activity activity, List<RecordListBean.Data> list) {
        this.activity = activity;
        this.list = list;
    }

    @Override
    public int getCount() {
        if (list != null && list.size() > 0) {
            return list.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(activity).inflate(R.layout.item_records_list_listview, null);
        TextView recordName = (TextView) convertView.findViewById(R.id.item_listView_records_recordName);
        TextView time = (TextView) convertView.findViewById(R.id.item_listView_records_time);

        String recordNameStr = list.get(position).getRecordName();
        String titleName = recordNameStr.substring(0, recordNameStr.length() - 36);
        recordName.setText(titleName);
        time.setText(DateUtils.getStrTime(String.valueOf(list.get(position).getTimeStamp())));

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("recordId", String.valueOf(list.get(position).getId()));
                bundle.putString("recordNameStr", list.get(position).getRecordName());
                JumpUtils.jumpActivity(activity, RecordDetailsActivity.class, bundle);
            }
        });
        return convertView;
    }


}
